package com.song.fastdfs;

import java.io.File;
import java.io.FileInputStream;

import javax.servlet.http.HttpServletRequest;

import org.csource.fastdfs.StorageClient;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import basic.fastdfs.FastDFSLoad;

@Controller
@RequestMapping(value = "/fastdfs")
public class FastDFSController {

	
	//文件打包下载
	@RequestMapping("/upload")
    public void downLoadFiles(HttpServletRequest request)throws Exception {
		MultipartHttpServletRequest multipart= (MultipartHttpServletRequest) request;
		MultipartFile file = multipart.getFile("file");
		System.out.println(file);
		StorageClient storageClient = FastDFSLoad.load();
		File content = new File("D:\\download1.png");
        FileInputStream fis = new FileInputStream(content);
        byte[] file_buff = null;
        if (fis != null) {
            int len = fis.available();
            file_buff = new byte[len];
            fis.read(file_buff);
        }
        
		String[] upload_file = storageClient.upload_file(file_buff, "png", null);
		System.out.println(upload_file[0]);
		System.out.println(upload_file[1]);
    }
	
	//文件打包下载
	@RequestMapping("/init")
	public ModelAndView init()throws Exception {
		ModelAndView model=new ModelAndView();
		model.setViewName("/fastdfs/fastdfs_index");
		return model;
		
	}

  
	
}
